#ifndef __DYNA_TABLE_H
#define __DYNA_TABLE_H

#include "stdbool.h"


#ifndef MINE_DATA_DEFINE
#define MINE_DATA_DEFINE

typedef unsigned int    u32;
typedef unsigned short  u16;
typedef unsigned char   u8;

typedef signed   int 	s32;
typedef signed short 	s16;
typedef signed  char 	s8;

#endif





#define PENDING_EN
//#define FUNC_DEBUG
#define TIMER_CALL_BACK 
 
 
#ifdef  PENDING_EN
#ifndef TASK_NUM
#define TASK_NUM 32
#endif
#endif

#if 1
struct buf_public_def
{
	bool  is_full;
	u16 buf_size;
	u16 put_index;
	u16 get_index;
#ifdef FUNC_DEBUG
	u16 max_index;
#endif	
};
#endif


#ifndef RT_NULL
#define RT_NULL 0
#endif


struct func_dyna_table_def
{
	struct buf_public_def parent;	
#ifdef  PENDING_EN
	u32 pending[ (TASK_NUM/32)+( (TASK_NUM%32)?1:0 ) ];
#endif	
	u8 (**func)(void);
};

struct timer_unit_def
{
	u16 cnt;
#ifdef TIMER_CALL_BACK
	void(*call_back)(void);
#endif
};

struct timer_dyna_table_def
{
	struct buf_public_def parent;
	struct timer_unit_def **timer;
};


#ifdef __cplusplus
extern "C" {
#endif

#ifdef PENDING_EN

extern void func_scheduler( struct func_dyna_table_def *obj );
extern void func_pending_self( struct func_dyna_table_def *obj );
extern void func_pending_task( struct func_dyna_table_def *obj, void *func  );
extern void func_resume_task( struct func_dyna_table_def *obj, void *func );

#endif

extern void func_table_distributed_run( struct func_dyna_table_def *obj );
extern void func_table_centralized_run( struct func_dyna_table_def *obj );
extern void func_table_delete( struct func_dyna_table_def *obj, u8 (*ptr)(void) );
extern s16  func_table_find( struct func_dyna_table_def *obj, u8 (*ptr)(void) );
extern u8   func_table_register( struct func_dyna_table_def *obj, u8 (*ptr)(void) );
extern u8 func_table_register_no_check(struct func_dyna_table_def *obj, u8 (*ptr)(void));

extern u8 timer_table_register(struct timer_dyna_table_def *obj, struct timer_unit_def *timer );
extern u8 timer_table_run(struct timer_dyna_table_def *obj );
extern u8 timer_table_del(struct timer_dyna_table_def *obj, struct timer_unit_def *timer );;


#ifdef __cplusplus
}
#endif

#endif



